(function ($) {
    $(function(){
        var
            oContent = $('#main .content');

        $(window).scroll(function(){
            var scrollTop = document.body.scrollTop||document.documentElement.scrollTop;
            var marTop = 420-scrollTop;
            oContent.css({marginTop:marTop});
            if(marTop<-40){
                oContent.css({marginTop:-40});
            }
        });

        var
            oOpacity = $ ('.opacity'),
            oP2   = $ ('.p2'),
            aLiList = $ ('.li-list li');
        aLiList.mouseenter(function(){
            var iIndex = $(this).index();
            oOpacity.eq(iIndex).css({display:'block'});
            oP2.eq(iIndex).css({display:'block'});
        });
        aLiList.mouseleave(function(){
            var iIndex = $(this).index();
             oOpacity.eq(iIndex).css({display:'none'});
            oP2.eq(iIndex).css({display:'none'});
        });
        var
            oHotP2   = $ ('.hot-p2'),
            oHotOpacity = $ ('.hot-opacity'),
            aHotList = $ ('.hot-list li');
        aHotList.mouseenter(function(){
            var iIndex = $(this).index();
            oHotOpacity.eq(iIndex).css({display:'block'});
            oHotP2.eq(iIndex).css({display:'block'});
        });
        aHotList.mouseleave(function(){
            var iIndex = $(this).index();
            oHotOpacity.eq(iIndex).css({display:'none'});
            oHotP2.eq(iIndex).css({display:'none'});
        });
        var
            aWomenLeft = $ ('.women-left li'),
            oWomenLOpacity = $ ('.women-left .womenL-opacity'),
            oWomenLP2 = $ ('.women-left .womenL-p2'),
            aWomenRight = $ ('.women-right li'),
            oWomenROpacity = $ ('.women-right .womenR-opacity'),
            oWomenRP2 = $ ('.women-right .womenR-p2');
        setOpacity2(aWomenLeft,oWomenLOpacity,oWomenLP2);
        setOpacity1(aWomenRight,oWomenROpacity,oWomenRP2);
        var
            aManLeft = $('.man-left li'),
            oManLP2 = $ ('.manAct .manL-p2'),
            oManLOpacity = $ ('.manAct .manL-opacity');
        setOpacity2(aManLeft,oManLP2,oManLOpacity);
        var
            aMeiZhaLeft = $('.meiZha-left li'),
            oMeiZhaP2 = $ ('.meiZha .meiZha-p2'),
            oMeiZhaOpacity = $ ('.meiZha .meiZha-opacity');

        setOpacity2(aMeiZhaLeft,oMeiZhaP2,oMeiZhaOpacity);

        var
            aJiaJuLeft = $('.jiaju-left li'),
            oJiaJuP2 = $ ('.jiaju-p2'),
            oJiaJuOpacity = $ ('.jiaju-opacity');
        setOpacity2(aJiaJuLeft,oJiaJuP2,oJiaJuOpacity);

        var
            aChildLeft = $('.childAct-left li'),
            oChildP2 = $ ('.childAct-p2'),
            oChildOpacity = $ ('.childAct-opacity');
        setOpacity2(aChildLeft,oChildP2,oChildOpacity);

        var
            aSubNavCont= $('.subNav-cont'),
            aSubNavLi = $('.act-Ready .subNav li'),
            oCont = $ ('.subNav-cont .cont'),
            oActOpacity = $ ('.subNav-cont .act-opacity'),
            oBack  =  $('.subNav-cont .back');
        aSubNavLi.click(function(){
            var iIndex = $(this).index();
            if(iIndex!=aSubNavLi.length-1){
                aSubNavLi.removeClass('border').eq(iIndex).addClass('border');
                aSubNavCont.css({display:'none'}).eq(iIndex).css({display:'block'})
            }
        });
        setOpacity1(oCont,oActOpacity,oBack);

        var
            oCont2 = $ ('.subNav-cont2 .cont'),
            oActOpacity2 = $ ('.subNav-cont2 .act-opacity'),
            oBack2  =  $('.subNav-cont2 .back'),
            oCont3 = $ ('.subNav-cont3 .cont'),
            oActOpacity3 = $ ('.subNav-cont3 .act-opacity'),
            oBack3  =  $('.subNav-cont3 .back'),
            oCont4 = $ ('.subNav-cont4 .cont'),
            oActOpacity4 = $ ('.subNav-cont4 .act-opacity'),
            oBack4  =  $('.subNav-cont4 .back'),
            oCont5 = $ ('.subNav-cont5 .cont'),
            oActOpacity5 = $ ('.subNav-cont5 .act-opacity'),
            oBack5  =  $('.subNav-cont5 .back');

        setOpacity1(oCont2,oActOpacity2,oBack2);
        setOpacity1(oCont3,oActOpacity3,oBack3);
        setOpacity1(oCont4,oActOpacity4,oBack4);
        setOpacity1(oCont5,oActOpacity5,oBack5);



        //无缝轮播
        var
            oImgList =  $('.banner .img_list'),
            aImgList =  $('.banner .img_list li'),
            Floag=true,
            LuniIndex = 0;

        var itimer;
        itimer=setInterval(function(){
            if (Floag){
                Floag=false;
                LuniIndex++;
                oImgList.animate({left:-1880*(LuniIndex)},function(){
                    Floag=true;
                    if(LuniIndex == 1){
                        oImgList.css({left:-1880})
                    }
                });
                if(LuniIndex == aImgList.length - 1) {
                    LuniIndex =1;
                }
            }
        },3000);


        //封装函数
        //透明度和显示影藏
        function setOpacity1(attr,obj2,obj3 ){
            attr.mouseenter(function(){
                var iIndex = $(this).index();
                obj2.eq(iIndex).css({display:'block'});
                obj3.eq(iIndex).css({display:'block'});
            });
            attr.mouseleave(function(){
                var iIndex = $(this).index();
                obj2.eq(iIndex).css({display:'none'});
                obj3.eq(iIndex).css({display:'none'});
            });
        }
        //透明度和显示影藏index-1
        function setOpacity2(attr,obj2,obj3 ){
            attr.mouseenter(function(){
                var iIndex = $(this).index();
                if(iIndex>0){
                    obj2.eq(iIndex-1).css({display:'block'});
                    obj3.eq(iIndex-1).css({display:'block'});
                }
            });
            attr.mouseleave(function(){
                var iIndex = $(this).index();
                if(iIndex>0){
                    obj2.eq(iIndex-1).css({display:'none'});
                    obj3.eq(iIndex-1).css({display:'none'});
                }
            });
        }


    })
})(jQuery);
